<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2018-03-02 17:14:35 apple $
 模板消息相关函数
*/
namespace core;
defined('BY_JYA') or exit('error');
class msg_tpl{
	//检索插件全局模板
	public function check_tpl($pluginname){
		$msgtpl=pdo_getcolumn('core_plugins',array('name'=>$pluginname),'msgtpl');
		if($msgtpl){
			$msgtpl=json_decode($msgtpl,true);
			if(count($msgtpl)){
				foreach($msgtpl as $item){
					$isaddid=pdo_getcolumn('core_tpl_template',array('plugin_name'=>$pluginname,'name'=>$item['name']),'id');
					$data=array(
						'title'=>$item['title'],
						'template_name'=>$item['template_name'],
						'appsubtpl_name'=>$item['appsubtpl_name'],
						'first'=>$item['first'],
						'firstcolor'=>$item['firstcolor'],
						'keywords'=>ijson_encode($item['keywords']),
						'footer'=>$item['footer'],
						'footercolor'=>$item['footercolor'],
						'remark'=>$item['remark'],
						'demo'=>$item['demo'],
						'demoappsub'=>$item['demoappsub'],
						'kefumsg'=>$item['kefumsg'],
					);
					if($isaddid){
						pdo_update('core_tpl_template',$data,array('id'=>$isaddid));
					}else{
						$data['name']=$item['name'];
						$data['plugin_name']=$pluginname;
						pdo_insert('core_tpl_template',$data);
					}
				}
				
			}
		}
		return true;
	
	}
	//获取微信模板
	public function get_wxtpl($pluginname=''){
		$token =  cfc('account')->getAccessToken();
		$url = 'https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=' . $token;
		$c =  cfc('http')->ihttp_post($url,'');
		$result = @json_decode($c['content'], true);
		return $result ;
	}
}